package cool.qingqing.Myplan.controller;


import cool.qingqing.Myplan.entity.Daily;
import cool.qingqing.Myplan.exception.MyPlanEnum;
import cool.qingqing.Myplan.exception.MyPlanException;
import cool.qingqing.Myplan.mapper.DailyMapper;
import cool.qingqing.Myplan.service.IDailyService;
import cool.qingqing.result.Result;
import cool.qingqing.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaoshanqing
 * @since 2021-12-25
 */
@RestController
@RequestMapping("/Myplan/daily")
public class DailyController {
	@Autowired
	private IDailyService dailyService;
	@Autowired
	private DailyMapper dailyMapper;

	@GetMapping("/all")
	public Result getDaily(@RequestParam("id") String id){
		if(id==null || "".equals(id)) {
			throw new MyPlanException(MyPlanEnum.PLANER);
		}
		return new Result<Daily>().setCode(ResultEnum.SUCCEED).setData(dailyService.list()).setMsg("请求成功"+dailyMapper.getCount());
	}

	/**
	 * 请求方式：get
	 * 请求地址：/Myplan/daily/hello
	 * 返回结果 code=0 msg=“成功”
	 */
	@GetMapping("/hello")
	public String getHello(){
		return "Hello gaogao";
	}

	/**
	 * 请求方式：post
	 * 请求地址：/Myplan/daily/addDaily
	 * 返回结果 code=0 msg=“成功”
	 */
	@PostMapping("addDaily")
	public Result addDaily(@RequestBody Daily daily){
		 if(dailyService.save(daily)){
		 	return new Result().setCode(ResultEnum.SUCCEED).setMsg("操作成功");
		 }else{
			return new Result().setCode(ResultEnum.FAIL).setMsg("操作失败");
		}
	}

}
